package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.exception.Assert;
import com.atguigu.srb.common.result.ResponseEnum;
import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.common.util.RegexValidateUtils;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.vo.LoginVO;
import com.atguigu.srb.core.pojo.vo.RegisterVo;
import com.atguigu.srb.core.pojo.vo.UserInfoQuery;
import com.atguigu.srb.core.pojo.vo.UserInfoVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author lsyandwh
 * @since 2022-12-02
 */
@Api(tags = "会员管理")
@RestController
@RequestMapping("/admin/core/userInfo")
//@CrossOrigin
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("用户列表")
    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable("page") Integer page,
                       @PathVariable("limit") Integer limit,
                       UserInfoQuery userInfoQuery){

        IPage<UserInfo> pageList = userInfoService.pageList(page,limit,userInfoQuery);

        return Result.ok().data("pageModel",pageList);
    }

    @ApiOperation("修改账户状态")
    @PutMapping("/lock/{id}/{status}")
    public Result lock(@PathVariable("id") Long id,@PathVariable("status") Integer status){

        userInfoService.lock(id,status);

        return Result.ok().message(status == 0 ? "锁定账户成功" : "解锁账户成功");
    }
}

